<!DOCTYPE html>
<html lang="en">
<head>
    <title>考勤公司级别</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-store, must-revalidate">
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT">
    <meta http-equiv="expires" content="-1">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="/dist/img/icon.png" type="image/x-icon">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="/dist/plugins/bootstrap/css/bootstrap.min.css">
    <!--字体-->
    <link rel="stylesheet" href="/dist/css/font-awesome.min.css">
    <!--图标-->
    <link rel="stylesheet" href="/dist/css/ionicons.min.css">
    <!--OA主样式-->
    <link rel="stylesheet" href="/dist/css/OA.min.css?t=e9c5bb62">
    <link rel="stylesheet" href="/dist/css/skins/OA-skins.min.css?t=66b457d6">
    <style>
        .bgOne {
            color: black;
        }

        .bgTwo {
            color: red;
        }

        .bgThree {
            color: #9d9d9d;
        }

        .nav-tabs-custom {
            padding: 10px;
            margin-bottom: 0;
            box-shadow: none;
            position: relative;
            overflow: hidden;
        }

        .moduleName {
            float: left;
            height: 27px;
            line-height: 27px;
            font-size: 22px;
            width: 100px;
            text-align: center;
        }

        .lineOne {
            text-align: left;
        }

        .lineOne span {
            max-height: 20px;
            line-height: 20px;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 1;
            text-align: left;
        }

        .infoReport {
            width: 160px;
            margin: 0 auto;
            text-align: left;
            margin-top: 10px;
        }

        .infoReport div {
            margin: 10px 0;
        }
    </style>
</head>
<body>
<section class="content" id="app" v-cloak>
    <div class="oaLoad">
        <div class="loadGif" id="areaProgress"></div>
    </div>
    <iframe id="ifExprot" style="width:0px;height:0px;display: none;" frameborder="0"></iframe>
    <div class="nav-tabs-custom oaReportNav">
        <!-- Tabs within a box -->
        <div class="moduleName">考&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;勤</div>
        <ul class="nav nav-tabs pull-right" style="margin-bottom: 10px;" v-cloak>
            <li :class="isActive(today)?'active':''" @click="refreshData('sign','get_signInCompany',today)"><a
                    href="#sales-chart" data-toggle="tab">今日</a></li>
            <!--<li :class="isActive(yesterday)?'active':''" @click="refreshData('sign','get_signInCompany',yesterday)"><a href="#sales-chart" data-toggle="tab">昨日</a></li>
           -->
            <!--<li :class="isActive(thisWeek)?'active':''" @click="refreshData('sign','get_signInCompany',thisWeek)"><a href="#sales-chart" data-toggle="tab">本周</a></li>-->
            <li :class="isActive(thisMonth)?'active':''" @click="refreshData('sign','get_signInCompany',thisMonth)"><a
                    href="#sales-chart" data-toggle="tab">本月</a></li>
            <li :class="isActive(item.time)?'active':''" v-for="(item,i) in tab"
                @click="refreshData('sign','get_signInCompany',item.time)"><a href="#sales-chart" data-toggle="tab">{{i==0?"上月":item.str}}</a>
            </li>
            <div class="infoReport" style="margin-top: 0px;">
                <div style="height: 25px;margin-bottom: 10px;margin-top: 0px;">
                    <input type="button" class="btn oaBtn btn-sm pull-left"
                           style="margin-left: 0px; position:absolute; right:10px; !important;" value="导出考勤明细"
                           v-if="sign.time.length==7"
                           @click="exportGet"/>
                </div>
            </div>
        </ul>
    </div>
    <div style="padding: 0 10px;background: #fff;overflow: hidden" id="signInCompany">
        <div style="width: 100%;float:left;" class="mScrollBox">

            <table class="table text-center table-width ">
                <thead>
                <tr>
                    <!--<td style="width: 5%">序号</td>-->
                    <td :style="sign.time.length==10?'width: 19%':'width: 10%'">部门/大区</td>
                    <td :style="sign.time.length==10?'width: 19%':'width: 10%'" v-if="sign.time.length!=10">岗位</td>
                    <td :style="sign.time.length==10?'width: 19%':'width:8%'" v-if="sign.time.length!=10">姓名</td>
                    <td :style="sign.time.length==10?'width: 19%':'width:8%'">应出勤</td>
                    <td :style="sign.time.length==10?'width: 19%':'width:8%'">出勤</td>
                    <td :style="sign.time.length==10?'width: 19%':'width:8%'">请假</td>
                    <td :style="sign.time.length==10?'width: 19%':'width:8%'">缺勤</td>
                    <td style="width: 35%;" v-if="sign.time.length!=10">区域</td>
                </tr>
                </thead>
                <tbody>
                <tr v-for="(item,i) in sign.list">
                    <!--<td>{{i+1}}</td>-->
                    <template v-if="sign.time.length==10">
                        <td style="color:#169BD5;cursor: pointer;border-right: 1px solid rgb(203, 203, 205)" @click="openSignInDepart(item)">
                            {{item.departName}}
                        </td>
                    </template>
                    <template v-else>
                        <td :rowspan="item.departNamespan" :class="{hidden: item.departNamedis}" style="border-right: 1px solid rgb(203, 203, 205)">{{item.departName}}
                        </td>
                    </template>
                    <td :rowspan="item.roleNamespan" :class="{hidden: item.roleNamedis}" v-if="sign.time.length!=10" style="border-right: 1px solid rgb(203, 203, 205)">
                        {{item.roleName}}
                    </td>
                    <td style="color:#169BD5;cursor: pointer" @click="openSignInPersonal(item)"
                        v-if='sign.time.length!=10'>
                        {{item.userName}}
                    </td>
                    <td>{{item.shouldCount=='0'?"-":item.shouldCount}}</td>
                    <td v-if="sign.time==today"
                        @click="openSignInList('depart',item.departId,1)" style="color:#2a8cec;cursor: pointer;">
                        {{item.signInCount=='0'?"-":item.signInCount}}
                    </td>
                    <td v-else @click="openSignInList('user',item.userId,1)" style="color:#2a8cec;cursor: pointer;">
                        {{item.signInCount=='0'?"-":item.signInCount}}
                    <td v-if="sign.time==today"
                        @click="openSignInList('depart',item.departId,2)" style="color:#2a8cec;cursor: pointer;">
                        {{item.leaveCount=='0'?"-":item.leaveCount}}
                    </td>
                    <td v-else @click="openSignInList('user',item.userId,2)" style="color:#2a8cec;cursor: pointer;">
                        {{item.leaveCount=='0'?"-":item.leaveCount}}
                    <td v-if="sign.time==today"
                            @click="openSignInList('depart',item.departId,3)" style="color:red;cursor: pointer;">
                        {{item.absenceCount}}
                    </td>
                    <td v-else style="color:red;">-</td>
                    <td style="text-align: left;" :rowspan="item.regionNamespan" :class="{hidden: item.regionNamedis}"
                        v-if="sign.time.length!=10">{{item.regionName}}
                    </td>
                </tr>
                <tr>
                    <td>合计</td>
                    <td v-if="sign.time.length!=10">--</td>
                    <td v-if="sign.time.length!=10">--</td>
                    <td>{{sign.info.shouldCount}}</td>
                    <td>{{sign.info.signInCount}}</td>
                    <td>{{sign.info.leaveCount}}</td>
                    <td>{{sign.info.absenceCount}}</td>
                    <td v-if="sign.time.length!=10">-</td>
                </tr>
                </tbody>
            </table>
        </div>
        <!--<div style="width: 20%;float:right;">-->
        <!--  <div class="infoReport" style="margin-top: 0px;">
              <div style="height: 25px;margin-bottom: 10px;margin-top: 0px;">
                  <input type="button" class="btn oaBtn btn-sm pull-left" style="margin-left: 0px;" value="导出考勤明细"
                         v-if="sign.time!=today"
                         @click="exportGet"/>
              </div>
          </div>-->
        <!--<div>应出勤(总)：{{sign.info.shouldCount}}</div>-->
        <!--<div>已出勤(总)：{{sign.info.signInCount}}</div>-->
        <!--<div>请&nbsp;&nbsp;&nbsp;&nbsp;假(总)：{{sign.info.leaveCount}}</div>-->
        <!--<div>缺&nbsp;&nbsp;&nbsp;&nbsp;勤(总)：{{sign.info.absenceCount}}</div>-->
        <!--
                    </div>

                </div>-->
    </div>
    <!-- /.box-body -->
</section>
<!--JQ-->
<script src="https://file.ggxqce.com/web/jquery-2.2.3.min.js"></script>
<!--插件JS-->
<script src="https://file.ggxqce.com/web/bootstrap.min.js"></script>
<!--框架已定义 JS-->
<script src="/dist/js/app_iframe.js?t=0b5caf39"></script>
<!--oa自定义  JS-->
<script src="/dist/js/oa.js?t=0c4d95a9"></script>
<script type="text/javascript" src="/dist/plugins/My97DatePicker/WdatePicker.js"></script>
<script src="https://file.ggxqce.com/web/vue.min.js"></script>
<script type="text/javascript">
    var app = new Vue({
        el: '#app',
        data: {
            companyId: $.wyui.page.urlParams.companyId ? $.wyui.page.urlParams.companyId : getCurrentUser().companyId,
            yesterday: new Date(new Date() - 24 * 60 * 60 * 1000).Format("yyyy-MM-dd"),
            today: new Date().Format("yyyy-MM-dd"),//今天
            hour: new Date().getHours(),
            thisMonth: new Date().Format("yyyy-MM"),
            thisWeek: new Date().Format("yyyy-MM-dd") + "-w",
            tab: [],
            sign: {
                time: $.wyui.page.urlParams.dateTime ? $.wyui.page.urlParams.dateTime : new Date().Format("yyyy-MM-dd"),
                list: [],
                info: {}
            },
        },
        methods: {
            //获取tab
            //获取合计
            getCount: function (arr, key) {
                var number = 0;
                for (var i = arr.length - 1; i >= 0; i--) {
                    number += (arr[i][key] && arr[i][key] != '-' ? arr[i][key] : 0)

                }
                return number;
            },
            openSignInList: function (type1, typeId, type2) {
//                getForSignInByTypeAndDateTime
                var that = this;
                var title;
                if (type2 == 1) {
                    title = "出勤人数";
                    url = "/reportForm/signIn/signInList.html?type1=" + type1 + "&type2=" + type2 + "&typeId=" + typeId + "&dateTime=" + that.sign.time;
                    top.closeTabByPageId("signInList");
                    top.addTabs({id: "signInList", title: title, close: true, url: url});
                } else if (type2 == 2) {
                    title = "请假人数";
                    url = "/reportForm/signIn/leaveList.html?type1=" + type1 + "&type2=" + type2 + "&typeId=" + typeId + "&dateTime=" + that.sign.time + '&t=' + new Date()
                    top.closeTabByPageId("leaveList");
                    top.addTabs({id: "leaveList", title: title, close: true, url: url});
                } else if (type2 == 3) {
                    title = "缺勤人数";
                    url = "/reportForm/signIn/unSignInList.html?type1=" + type1 + "&type2=" + type2 + "&typeId=" + typeId + "&dateTime=" + that.sign.time + '&t=' + new Date()
                    top.closeTabByPageId("unSignInList");
                    top.addTabs({id: "unSignInList", title: title, close: true, url: url});
                }
            },
            getTab: function () {
                var that = this;
                var dateTime = new Date().Format("yyyyMM");
                for (var i = 0; i < 5; i++) {
                    dateTime = that.getLastEndMonth(dateTime);
                    that.tab.push(that.insert_flg(dateTime, "-", "4"))
                }
                console.log(that.tab)
            },
            getLastEndMonth: function (beginYearMonth) {
                var strYear = parseInt(beginYearMonth.substr(0, 4), 10);
                var strMonth = parseInt(beginYearMonth.substr(4, 6), 10);
                if (strMonth - 1 == 0) {
                    strYear -= 1;
                    strMonth = 12;
                } else {
                    strMonth -= 1;
                }
                if (strMonth < 10) {
                    strMonth = "0" + strMonth;
                }
                var monthstr = strYear + "" + strMonth;
                return monthstr;
            },
            //格式化日期
            insert_flg: function (str, flg, sn) {
                var newstr = "";
                for (var i = 0; i < str.length; i += sn) {
                    var tmp = str.substring(i, i + sn);
                    newstr += tmp + flg;
                }
                newstr = newstr.substr(0, newstr.length - 1);
                var st1 = newstr.substr(2, 2);
                var st2 = newstr.substr(5, 2);
                var newstr3 = st2 + "-" + st1;
                var obj = {str: newstr, time: newstr};
                return obj;
            },
            //tab中点击日期刷新对应数据
            refreshData: function (dataType, fun, time) {
                var that = this;
                that[dataType].time = time;
                that[fun]();
            },
            isActive: function (item) {
                var that = this;
                if (that.sign.time == item) {
                    return true;
                }
            },
            tablesMergeCell: function (list) {
                for (field in list[0]) {
                    var k = 0;
                    while (k < list.length) {
                        list[k][field + 'span'] = 1;
                        list[k][field + 'dis'] = false;
                        for (var i = k + 1; i <= list.length - 1; i++) {
                            if (list[k][field] == list[i][field] && list[k][field] != '') {
                                list[k][field + 'span']++;
                                list[k][field + 'dis'] = false;
                                list[i][field + 'span'] = 1;
                                list[i][field + 'dis'] = true;
                            } else {
                                break;
                            }
                        }
                        k = i;
                    }
                }
                return list;
            },
            //获取费用报表-区域经理
            get_signInCompany: function () {
                var that = this;

                $.wyui.postLoadMethod(urlConfig.report.attendance.getForCompanyByUserIdAndDateTime, {
                    "companyId": that.companyId,
                    "dateTime": that.sign.time
                }, function (data) {
                    console.log(data);
//                    var data=trimRN2(data);
                    that.sign.list = that.tablesMergeCell(data);
                    that.sign.info.shouldCount = that.getCount(that.sign.list, "shouldCount");
                    that.sign.info.signInCount = that.getCount(that.sign.list, "signInCount");
                    that.sign.info.leaveCount = that.getCount(that.sign.list, "leaveCount");
                    that.sign.info.absenceCount = that.getCount(that.sign.list, "absenceCount");
                }, false, true);
            },
            //查看考勤 部门详情页面
            openSignInDepart: function (item) {
                var that = this;
                top.closeTabByPageId("openSignInDepart");
                top.addTabs({
                    id: "openSignInDepart",
                    title: item.departName + "考勤详情",
                    close: true,
                    url: '/reportForm/signIn/signInDepart.html?departId=' + item.departId + "&dateTime=" + that.sign.time
                });
            },
            //查看考勤 个人详情页面
            openSignInPersonal: function (item) {
                var that = this;
                top.closeTabByPageId("openSignInPersonal");
                top.addTabs({
                    id: "openSignInPersonal",
                    title: item.userName + "考勤详情",
                    close: true,
                    url: '/reportForm/signIn/signInPersonal.html?userId=' + item.userId + "&dateTime=" + that.sign.time
                });
            },
            exportGet: function () {
                var that = this;
                $('#ifExprot').attr('src', server.ip
                    + "/attendance/downExcelSignIn.json"
                    + '?dateTime=' + that.sign.time
                    + '&companyId=' + that.companyId
                )
                ;
                return false;
            },
        },
        mounted: function () {
            var that = this;
            //1.获取前5个月的tab数据
            this.getTab();
            this.get_signInCompany();
        }
    });
</script>

</body>
</html>